define(['common','captcha'], function(common,captcha){
    var login = {
        submit : function(selector){
            $(document).on('submit', selector, function() {
                var self = $(this);
                $.post($(this).attr('action'), $(this).serialize(), function(res, status, xhr) {
                    if(res.code == 1){
                        window.location.href = res.url;
                    }else{
                        login.error("#captcha-user","#captcha-image");
                        common.toastMini(res.msg);
                    }
                });
                return false;
            });
        },
        error : function(elInput,elImage){
            captcha.imageValue(elInput,null);
            captcha.imageRefresh(elImage);
        }
    };
    captcha.image('#captcha-image');
    login.submit('form[data-toggle="login"]');
    return login;
});